package com.example.gyk.neteaseanimation;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;

import com.example.gyk.neteaseanimation.speedanimation.CustomSpeedView;

import java.util.Random;

public class SpeedActivity extends AppCompatActivity {
    private CustomSpeedView cs;
    private Button bt_click;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_speed);
        cs = findViewById(R.id.cs);
        bt_click = findViewById(R.id.bt_click);
        bt_click.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new Handler().postDelayed(runnable, 1000);
            }
        });
    }

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            int max = 14;
            int min = -2;
            Random random = new Random();
            int s = random.nextInt(max) % (max - min + 1) + min;
            cs.startAnimal(s);
            new Handler().postDelayed(runnable, 1000);
        }
    };
}